package com.ghsc.ghxc.jsb.ui.live.view

import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cn.appcore.ext.getCompatColor
import com.cn.appcore.utils.GlideUtil
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BottomPopupView
import com.lxj.xpopup.enums.PopupAnimation
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.ui.live.bean.LiveUserInfoBean

/**
 * 项目：JingShortVideo
 * 包名：com.bbl.jyShortVideo.ui.video.live.view
 * 类名：LiveAudienceListPopupView
 * 创建时间：2022/12/20 12:25
 * 创建人 @author： xiaolin
 * 描述 ：Todo...全部观众列表
 */
class LiveAudienceListPopupView  (context: AppCompatActivity, mList :MutableList<LiveUserInfoBean>, isLiveStr:String, vid:String, anchorId:String) : BottomPopupView(context) {
    private val mContext = context
    override fun getImplLayoutId() = R.layout.live_audience_list
    var mList = mList
    val isLiveStr=isLiveStr
    val vid=vid
    val anchorId=anchorId //主播id
    val mAdapter = ListAdapter(isLiveStr)

    override fun onCreate() {
        super.onCreate()
        var  rvList= findViewById<RecyclerView>(R.id.rvList)
        rvList.layoutManager = LinearLayoutManager(mContext)
        rvList.adapter = mAdapter
        mAdapter.replaceData(mList)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            //todo 某个用户
//            XPopup.Builder(mContext)
//                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
//                .customHostLifecycle(lifecycle)
//                .dismissOnTouchOutside(true)
//                .navigationBarColor(mContext.getCompatColor(R.color.bg_dark_color))
//                .asCustom(
//                    LiveUserInfoPopupView(mContext,mAdapter.getItem(position).uid,vid,anchorId)
//                )
//                .show()
        }
    }
    override fun onDestroy() {
        super.onDestroy()
    }
    override fun getMaxWidth() = 0
    class ListAdapter(isLiveStr:String)  : BaseQuickAdapter<LiveUserInfoBean, BaseViewHolder>(
        R.layout.live_count_item) {
//        // 预加载回调
//        var onPreload: (() -> Unit)? = null
//        // 预加载偏移量
//        var preloadItemCount = 0

        var isLiveStr =""
        init {
            this.isLiveStr=isLiveStr
        }
        override fun convert(helper: BaseViewHolder, item: LiveUserInfoBean) {
            GlideUtil.ImageLoad(this.context, item.headimg, helper.getView(R.id.imgHead))
            helper.setText(R.id.tvName, item.nickname)

            var tvId= helper.getView<TextView>(R.id.tvId)
            if (helper.layoutPosition==0){
                tvId.text="1"
                tvId.setTextColor(this.context.getCompatColor(R.color.red))
            }else if (helper.layoutPosition==1){
                tvId.text="2"
                tvId.setTextColor(this.context.getCompatColor(R.color.task_color))
            }else if (helper.layoutPosition==2){
                tvId.text="3"
                tvId.setTextColor(this.context.getCompatColor(R.color.btn_default_color))
            }else {
                tvId.text="-"
                tvId.setTextColor(this.context.getCompatColor(R.color.task_color_btn_false))
            }
//            if (item.level==0)
//                helper.setGone(R.id.levelBg,true)
//            else {
//                helper.setImageResource(R.id.levelBg, CharRongYunUtils.setImageLevelId(item.level))
//                    .setGone(R.id.levelBg,false)
//            }


//            if(isLiveStr == LivePrototype.Role.ANCHOR.value){
//                helper.setGone(R.id.tvPrice,false)
//                    .setText(R.id.tvPrice,item.price.toString()+" KMC")
//            }else  helper.setGone(R.id.tvPrice,true)

        }

//        override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
//            super.onBindViewHolder(holder, position)
//            if ((itemCount-preloadItemCount) == position){
//                onPreload?.invoke()
//            }
//        }
    }
}